#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:
    string gcdOfStrings(string str1, string str2) {
        if (str1 + str2 == str2 + str1) {
            int len1 = str1.length();
            int len2 = str2.length();
            auto elem = minmax(len1, len2);
            return str1.substr(0, GetMaxCommodIdx(elem.second, elem.first));
        } else {
            return "";
        }
    }

    int GetMaxCommodIdx(int a, int b)
    {
        int ret{};
        while (a % b != 0) {
            int tmp = b;
            b = a % tmp;
            a = tmp;
        }
        return b;
    }
};

int main()
{
    Solution s;
    //cout << s.GetMaxCommodIdx(45, 25) << endl;
    cout << s.gcdOfStrings("TAUXXTAUXXTAUXXTAUXXTAUXX", "TAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXX") << endl;

    return 0;
}